package com.virtium.vpc.action.controller;

import java.util.ArrayList;
import java.util.Iterator;

import com.virtium.vpc.dao.DAOFactory;
import com.virtium.vpc.dao.VpcRamdensityDAO;
import com.virtium.vpc.hibernate.model.VpcRamdensity;

public class VpcRamdensityManager {
	private static ArrayList<VpcRamdensity> arrVpcRamdensity = null;

	public static ArrayList<VpcRamdensity> getAll() {
		try {
			if (arrVpcRamdensity != null && arrVpcRamdensity.size() > 0)
				return arrVpcRamdensity;
			VpcRamdensityDAO vpcRamdensity = DAOFactory.getInstance()
					.getVpcRamdensityDAO();
			arrVpcRamdensity = new ArrayList<VpcRamdensity>();
			arrVpcRamdensity.addAll(vpcRamdensity.findAll());
		} catch (Exception ex) {
		}
		return arrVpcRamdensity;
	}
	
	public static String getTextByID(int id){
		getAll();
		Iterator<VpcRamdensity> iterObject = arrVpcRamdensity.listIterator();
		while(iterObject.hasNext()){
			VpcRamdensity object = iterObject.next();
			if(object.getId().equals(id))return object.getText();
			
		}
		return "";
	}
	
	public static void AddNew(String text){
		try{
			VpcRamdensity object = new VpcRamdensity();
			object.setText(text);
			VpcRamdensityDAO ObjectDAO = DAOFactory.getInstance().getVpcRamdensityDAO();
			ObjectDAO.save(object);
			arrVpcRamdensity = null;
		}catch(Exception ex){
			
		}
	}
	
	public static void Delete(int id){
		try{
			
			VpcRamdensityDAO ObjectDAO = DAOFactory.getInstance().getVpcRamdensityDAO();
			VpcRamdensity object = ObjectDAO.findById(id);
			ObjectDAO.delete(object);
			arrVpcRamdensity = null;
		}catch(Exception ex){
			
		}
	}
}
